package BLL;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; 
import java.util.logging.FileHandler;  
import java.util.logging.Level;  
import java.util.logging.Logger;  
import java.util.logging.SimpleFormatter;  
import com.kook.ball.util.*;
import com.kook.ball.configure.*;
/**
 * Servlet implementation class SendRequest
 */
@WebServlet("/SendRequest")
public class SendRequest extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SendRequest() {
        super();
        // TODO Auto-generated constructor stub
    }
    protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
    	GenerateRandomString verify=new GenerateRandomString();
    	String ReferenceCode=verify.getAlphaNumeric(4);
    	String VerifyCode=verify.getAlphaNumeric(4);
        
    	SendMail mail=new SendMail();
    	HttpSession session = request.getSession();
    	session.setAttribute("VerifyCode",VerifyCode);
 		request.getSession().setAttribute("VerifyCode", VerifyCode);
 		session.setAttribute("ReferenceCode",ReferenceCode);
 		request.getSession().setAttribute("ReferenceCode", ReferenceCode);
 		/*Logger logger = Logger.getLogger("MyLog");  
        FileHandler fh;  
        try {
        	fh = new FileHandler("logfile.log");  
            logger.addHandler(fh);  
            //logger.setLevel(Level.ALL);  
            SimpleFormatter formatter = new SimpleFormatter();  
            fh.setFormatter(formatter); 	
            logger.info("My VerifyCode log"+VerifyCode);
            logger.info("My ReferenceCode log"+ReferenceCode);
        	
        }
        catch (SecurityException e) {  
            e.printStackTrace();  
        } */
        response.sendRedirect("OTP.jsp");
    	
    }
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		processRequest(request, response);
	}

}
